﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetfractionHub.Network.Protocol;
using NetfractionHub.Network.Protocol.BASE.Factory;

namespace NetfractionHub.LocalMachine.BotCommands.Handler
{
    [CommandHandler("hubname", Description="Gets or sets the hub name.\nUsage:\nGet: <trigger>\nSet: <trigger> \"new name\"")]
    public class HubName : CommandHandler
    {
        public override BotReturnStatus HandleCommandMessage(NetfractionHub.RemoteMachine.Node source, CommandMessage message)
        {
            if (message.UnnamedArguments.Count == 0)
                return new BotReturnStatus(true, string.Format("Hub name: {0}", Settings.HubSettings.HubIdentity.Name)); // no security check needed, if they're logged in they can see the hub name anyway
            else if (message.UnnamedArguments.Count == 1)
                if (Security.Permission.HasPermission(source.SecurityIdentity, typeof(Security.Permissions.SetHubNamePermission)))
                {
                    Settings.HubSettings.HubIdentity.Name = message.UnnamedArguments[0];
                    return new BotReturnStatus(true, string.Format("{0} has set the hub name to: {1}", source.Identity.Nickname, message.UnnamedArguments[0]));
                }
                else
                    return new BotReturnStatus(false, Security.Permission.GetDeniedString(typeof(Security.Permissions.SetHubNamePermission)));
            else
                return new BotReturnStatus(false);
        }
    }
}
